import requests
import test
from bs4 import BeautifulSoup
def get_page(url):
    response = requests.get(url)
    if response.status_code == 200:
        return response.text
    return None

if __name__ == '__main__':
    # i为天数
    i = 30
    # p为哨兵标记，如p=946(5月1日)，p=916（4月1日）
    p = 900
    # 补充URL，使之能够遍历哨兵之后i天的所有url
    while i > 0:
        #天数加1
        p = p + 1
        # 补充为种子url
        url = "https://haoxiangta.com/n2021/" + 'h'+str(p) + '/'
        print(url)
        i = i - 1

        html = get_page(url)
        # 解析网页
        soup = BeautifulSoup(html,features="lxml")
        # print(soup.prettify()) # 输出整个网页 会比较工整
        # print(soup.find_all('a')) # 输出所以a标签
        t = 0
        for a in soup.find_all('a'):
            text = a.text
            t = t+1
            # print(text,i)
            # 获取想要得到的微博热搜
            if t>34 and t<=84:
                # print(text)
                # contest = text
                # weibo.weibo_spider(context)
                test.baidu(text)




